import { Modal } from "antd";
import DynamicQueryTable, { SelectionType } from "@/components/report/DynamicQueryTable";
import { useState } from "react";
import type { Supplier } from "@/pages/base/supplier/entity";

interface SingleSupplierSelectorProps {
	open: boolean;
	onCancel: () => void;
	onOk: (selectedSupplier?: Supplier) => void;
}

const SingleSupplierSelector:React.FC<SingleSupplierSelectorProps> = ({ open, onCancel, onOk }) => {
  
  // 选中的供应商
  const [selectedSupplier, setSelectedSupplier] = useState<Supplier>();

  const handleOk = () => {
		onOk(selectedSupplier);
	};

	return (
		<Modal title="选择供应商" open={open} onCancel={onCancel} onOk={handleOk} width={800} destroyOnClose>
			<DynamicQueryTable 
        reportCode="supplier_select_report"
        selectionType={SelectionType.RADIO}
        onSelectChange={(selectedRows) => {setSelectedSupplier(selectedRows[0])}}  
      />
		</Modal>
	);
}

export default SingleSupplierSelector;